package com.maxd.respository.userMoney;

import com.maxd.model.HelpUserScore;
import com.maxd.model.UserMoney;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface UserMoneyRepository extends Repository<UserMoney, Long> {

    @Query(value = "select * from user_money t where t.user_id=:userId",nativeQuery = true)
    UserMoney selectById(@Param("userId") Long userId);


    @Transactional
    @Modifying
    @Query(value = "update user_money set money=money+:money where user_id=:userId",nativeQuery = true)
    Integer updateMoneyAdd(@Param("userId") Long userId,@Param("money") Double money);

    @Transactional
    @Modifying
    @Query(value = "update user_money set money=money-:money where user_id=:userId",nativeQuery = true)
    Integer updateMoneySub(@Param("userId") Long userId,@Param("money") Double money);

    @Transactional
    @Modifying
    @Query(value = "update user_money set money=money+:money,cannot_money=cannot_money+:cannot_money where user_id=:userId",nativeQuery = true)
    Integer updateMoneyAddTwo(@Param("userId") Long userId,@Param("money") Double money,@Param("cannot_money") Double cannot_money);

    @Transactional
    @Modifying
    @Query(value = "update user_money set cannot_money=cannot_money-:cannot_money where user_id=:userId",nativeQuery = true)
    Integer updateMoneySubTwo(@Param("userId") Long userId,@Param("cannot_money") Double cannot_money);


    @Transactional
    @Modifying
    @Query(value = "update user_money set cannot_money=cannot_money+:money where user_id=:userId",nativeQuery = true)
    void updateMoneyById(@Param("userId") Long userId,@Param("money") Double money);


    @Transactional
    @Modifying
    @Query(value = "update user_money set cannot_money=:money where user_id=:userId",nativeQuery = true)
    void updateCannotMoney(@Param("userId") Long userId,@Param("money") Double money);

    @Transactional
    @Modifying
    @Query(value = "update user_money set money=:money where user_id=:userId",nativeQuery = true)
    void updateMoney(@Param("userId") Long userId,@Param("money") Double money);

}
